<template>
  <div class="search-history">
    <van-cell title="搜索历史">
      <div v-if="isDeleteShow">
        <span @click="$emit('delAllHistorys')"
          >全部删除</span
        >&nbsp;&nbsp;&nbsp;&nbsp;
        <span @click="isDeleteShow = false">完成</span>
      </div>
      <van-icon v-else name="delete" @click="isDeleteShow = true" />
    </van-cell>
    <van-cell
      v-for="(item, index) in searchHistories"
      :key="index"
      :title="item"
      @click="onSearchItemClick(item, index)"
    >
    <!-- 单条删除 标 -->
      <van-icon
        v-if="isDeleteShow"
        name="close"
        
      />
    </van-cell>
  </div>
</template>

<script>
export default {
  props: {
    searchHistories: {
      type: Array,
      required : true
    },
  },
  data() {
    return {
      isDeleteShow: false,
    };
  },
  methods: {
    // 删除单条历史记录
    onSearchItemClick(item, index) {
      // 删除状态 删除
      if ((this.isDeleteShow)) {
        this.searchHistories.splice(index, 1);
      } else {
        //不在删除状态
        this.$emit('search',item)
      }
    },
  },
};
</script>

<style>
</style>